package com.cn.wanxi.controller;

import com.cn.wanxi.entity.NewsEntity;
import com.cn.wanxi.entity.ResultEntity;
import com.cn.wanxi.service.INewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/back/news")
public class NewsController {
    @Autowired
    private INewsService newsService;

    @RequestMapping("/add")
    protected ResultEntity add(NewsEntity newsEntity){
        return newsService.add(newsEntity);
    }

    @RequestMapping("/del")
    protected ResultEntity delete(NewsEntity newsEntity){
        return newsService.delete(newsEntity);
    }

    @RequestMapping("/get")
    protected ResultEntity findAll(NewsEntity newsEntity){
        return ResultEntity.success(newsService.findAll(newsEntity));
    }

    @RequestMapping("/id")
    protected ResultEntity findById(NewsEntity newsEntity){
        return newsService.findById(newsEntity);
    }

    @RequestMapping("/post")
    protected ResultEntity update(NewsEntity newsEntity){
        return newsService.update(newsEntity);
    }

    @RequestMapping("/count")
    protected ResultEntity getCount(NewsEntity newsEntity){
        int result = newsService.getCount(newsEntity);
        ResultEntity resultModel;
        if (result > 0) {
            resultModel = ResultEntity.success(result);
        } else {
            resultModel = ResultEntity.failed("查找总数失败");
        }
        return resultModel;
    }

    @RequestMapping("/previous")
    protected ResultEntity findPrevious(NewsEntity newsEntity){
        return newsService.findPrevious(newsEntity);
    }

    @RequestMapping("/next")
    protected ResultEntity findNext(NewsEntity newsEntity){
        return newsService.findNext(newsEntity);
    }
}
